package com.cyy.content.api;


import com.cyy.base.exception.ValidationGroups;
import com.cyy.base.model.PageParams;
import com.cyy.base.model.PageResult;
import com.cyy.content.model.dto.AddCourseDto;
import com.cyy.content.model.dto.CourseBaseInfoDto;
import com.cyy.content.model.dto.EditCourseDto;
import com.cyy.content.model.dto.QueryCourseParamsDto;
import com.cyy.content.model.po.CourseBase;
import com.cyy.content.service.CourseBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程基本信息 前端控制器
 * </p>
 *
 * @author cyy 课程信息编辑接口
 */
@Slf4j
@RestController
@Api(value = "课程信息编辑接口",tags = "课程信息编辑接口")
public class CourseBaseInfoController {

    @Autowired
    private CourseBaseService courseBaseService;

    @ApiOperation("课程查询接口")
    @RequestMapping("/course/list")
    public PageResult<CourseBase> list(PageParams pageParams,
                                       @RequestBody(required = false) QueryCourseParamsDto queryCourseParams){
//        CourseBase courseBase = new CourseBase();
//        courseBase.setName("测试名称");
//        courseBase.setCreateDate(LocalDateTime.now());
//        List<CourseBase> courseBases = new ArrayList();
//        courseBases.add(courseBase);
        return courseBaseService.queryCourseBaseList(pageParams, queryCourseParams);

    }


    @ApiOperation("新增课程基本信息")
    @PostMapping("/course")
    public CourseBaseInfoDto addCourseBaseInfo(@RequestBody @Validated({ValidationGroups.Insert.class}) AddCourseDto addCourseDto){
        //机构id，由于认证系统没有上线暂时硬编码
        Long companyId = 1232141425L;
        return courseBaseService.addCourseBaseInfo(companyId, addCourseDto);
    }

    @ApiOperation("查询课程基本信息")
    @GetMapping("/course/{courseId}")
    public CourseBaseInfoDto getCourseBaseInfo(@PathVariable Long courseId){
        return courseBaseService.getCourseBaseInfo(courseId);
    }

    @ApiOperation("编辑课程基本信息")
    @PutMapping("/course")
    public CourseBaseInfoDto editCourseBaseInfo(@RequestBody @Validated({ValidationGroups.Update.class}) EditCourseDto editCourseDto){
        //机构id，由于认证系统没有上线暂时硬编码
        Long companyId = 1232141425L;
        return courseBaseService.editCourseBaseInfo(companyId, editCourseDto);
    }


}
